﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace Sinacor.OMM.HealthMonitor.Entity.Common
{
    [Serializable()]
    public class ProcessData : IHealthDataReset
    {
        HealthEntityBase _healthEntityBase;
        public ProcessData()
        {
            _healthEntityBase = new HealthEntityBase();
        }

        public ProcessData(HealthEntityBase healthEntityBase)
        {
            _healthEntityBase = healthEntityBase;
        }

        //Limite
        long _limitPrivateMemory;//Private Memory
        int _limitHandleCount;//Handle Count
        int _limitThreadCount;//Thread Count

        //Informacao
        string _processName;//Process Name
        long _privateMemory;//Private Memory
        long _virtualMemory;//Virtual Memory
        int _handleCount;//Handle Count
        int _threadCount;//Thread Count
        TimeSpan _privilegedProcessorTime;//Privileged Processor Time
        TimeSpan _totalProcessorTime;//Total Processor Time
        DateTime _initializedDate;//Process Initialized
        TimeSpan _upTime;//Process Up Time
        string _machineName;//Nome da máquina
        string _machineIPAddress;//IP da máquina
        string _machineMacAddress;//MAC ADDRESS DA MAQUINA

        public long LimitPrivateMemory
        {
            get{return _limitPrivateMemory;}
            set
            {
                _limitPrivateMemory= value;
                _healthEntityBase.LastUpdate = DateTime.Now;
            }
        }
        public int LimitHandleCount
        {
            get { return _limitHandleCount; }
            set 
            { 
                _limitHandleCount = value;
                _healthEntityBase.LastUpdate = DateTime.Now;
            }
        }
        public int LimitThreadCount
        {
            get { return _limitThreadCount; }
            set 
            {
                _limitThreadCount = value;
                _healthEntityBase.LastUpdate = DateTime.Now;
            }
        }


        public string ProcessName
        {
            get { return _processName; }
            
            set 
            { 
                _processName = value;
                _healthEntityBase.LastUpdate = DateTime.Now;
            }
        }

        public long PrivateMemory
        {
            get { return _privateMemory; }
            set 
            { 
                _privateMemory = value;
                _healthEntityBase.LastUpdate = DateTime.Now;
            }
        }

        public long VirtualMemory
        {
            get { return _virtualMemory; }
            
            set 
            { 
                _virtualMemory = value;
                _healthEntityBase.LastUpdate = DateTime.Now;
            }
        }
        
        public int HandleCount
        {
            get { return _handleCount; }
            set 
            { 
                _handleCount = value;
                _healthEntityBase.LastUpdate = DateTime.Now;
            }
        }

        public int ThreadCount
        {
            get { return _threadCount; }
            set 
            { 
                _threadCount = value;
                _healthEntityBase.LastUpdate = DateTime.Now;
            }
        }


        public String PrivilegedProcessorTime
        {
            get { return _privilegedProcessorTime.ToString(); }
            set 
            { 
                _privilegedProcessorTime = TimeSpan.Parse(value);
                _healthEntityBase.LastUpdate = DateTime.Now;
            }
        }


        public String TotalProcessorTime
        {
            get { return _totalProcessorTime.ToString(); }
            set 
            { 
                _totalProcessorTime = TimeSpan.Parse(value);
                _healthEntityBase.LastUpdate = DateTime.Now;
            }
        }


        public DateTime InitializedDate
        {
            get { return _initializedDate; }
            set
            {
                _initializedDate = value;
                _upTime = DateTime.Now.Subtract(_initializedDate);
            }
        }


        public String UpTime
        {
            get { return _upTime.ToString(); }
        }


        public string MachineName
        {
            get { return _machineName; }
            set 
            {
                _machineName = value;
                _healthEntityBase.LastUpdate = DateTime.Now;
            }
        }


        public string MachineIPAddress
        {
            get { return _machineIPAddress; }
            set 
            { 
                _machineIPAddress = value;
                _healthEntityBase.LastUpdate = DateTime.Now;
            }
        }

        public string MachineMacAddress
        {
            get { return _machineMacAddress; }
            set
            {
                _machineMacAddress = value;
                _healthEntityBase.LastUpdate = DateTime.Now;
            }
        }

        private string _processId;

        public string ProcessId
        {
            get { return _processId; }
            set 
            {
                _processId = value;
                _healthEntityBase.LastUpdate = DateTime.Now;
            }
        }

        private string _threadId;

        public string ThreadId
        {
            get { return _threadId; }
            set 
            { 
                _threadId = value;
                _healthEntityBase.LastUpdate = DateTime.Now;
            }
        }

        public void Reset()
        {
            ProcessName = string.Empty;
            PrivateMemory = 0;
            VirtualMemory = 0;
            HandleCount = 0;
            ThreadCount = 0;
            PrivilegedProcessorTime = new TimeSpan(0).ToString();
            TotalProcessorTime = new TimeSpan(0).ToString();
            InitializedDate = DateTime.Now;
            MachineName = string.Empty;
            MachineIPAddress = string.Empty;
            MachineMacAddress = string.Empty;

        }
    }
}
